package tree;

/**
 * Created by iss on 17/8/3.
 */
public class Tree {
    public static Node root;


    public static void initTree(int[] ints) {

    }


    public static void middle(Node node) {
        if (node != null) {
            middle(node.left);
            System.out.println(node);
            middle(node.right);
        }
    }

    public static void front(Node node) {
        if (node != null) {
            System.out.println(node);
            front(node.left);
            front(node.right);
        }
    }

    public static void back(Node node) {
        if (node != null) {
            back(node.left);
            back(node.right);
            System.out.println(node);


        }
    }

    public static void find(Node node, int data) {
        if (node == null) {
            System.out.println("未查询到数据");
            return;
        }
        if (node.data == data) {
            System.out.println(node);
            return;
        }
        if (data < node.data) {
            if (node.left == null) {
                System.out.println("未查询到数据");
                return;
            }
            find(node.left, data);
        } else {
            if (node.right == null) {
                System.out.println("未查询到数据");
                return;
            }
            find(node.right, data);
        }
    }

    public static void main(String[] args) {
        Node root;
        Node right;
        Node left1;
        Node left;
        root = new Node(null, null, null, 50);
        left = new Node(null, null, null, 15);
        left1 = new Node(null, null, null, 3);
        right = new Node(null, null, null, 66);
        left1.parent = left;
        left.left = left1;
        left.parent = root;
        right.parent = root;
        root.left = left;
        root.right = right;

//        Tree.find(root, 15);

        Tree.middle(root);

        Tree.front(root);

        Tree.back(root);
    }
}
